/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import app.Global;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author yoshi
 */
public class TimeSlot {

    private long id;
    private Time from;
    private Time to;

    public TimeSlot(long id, Time from, Time to) {
        this.id = id;
        this.from = from;
        this.to = to;
    }

    public TimeSlot(ResultSet rs) {
        try {
            this.id = rs.getLong("id");
            this.from = rs.getTime("from");
            this.to = rs.getTime("to");
        } catch (SQLException ex) {
            Logger.getLogger(TimeSlot.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public Time getFrom() {
        return from;
    }

    public void setFrom(Time from) {
        this.from = from;
    }

    public long getId() {
        return id;
    }

    protected void setId(long id) {
        this.id = id;
    }

    public Time getTo() {
        return to;
    }

    public void setTo(Time to) {
        this.to = to;
    }

    public String toShortFormatString() {
        SimpleDateFormat hmDateFormat = Global.getDefaultHmDateFormat();

        return hmDateFormat.format(new Date(this.getFrom().getTime())) + " - " + hmDateFormat.format(new Date(this.getTo().getTime()));
    }

    public String toFormatString() {
        SimpleDateFormat hmDateFormat = Global.getDefaultHmDateFormat();
        StringBuilder builder = new StringBuilder(30)
            .append("Shift ")
            .append(this.getId())
            .append(" : ")
            .append(hmDateFormat.format(new Date(this.getFrom().getTime())))
            .append(" - ")
            .append(hmDateFormat.format(new Date(this.getTo().getTime())));
        return builder.toString();
    }
}
